package com.bracelet.controller;

import com.bracelet.beans.Msg;
import com.bracelet.beans.User;
import com.bracelet.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class RegisterController {
    @Autowired
    RegisterService registerService;

    @ResponseBody
    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public Msg Login(HttpServletRequest request){
        String username = (String) request.getAttribute("username");
        String password = (String) request.getAttribute("password");
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        boolean flag = registerService.register(user);
        if(flag == true){
            return Msg.success();
        }else{
            return Msg.fail();
        }

    }
}
